//
//  CloudSecondViewController.m
//  HelpThePoor
//
//  Created by van7ish on 2016/12/26.
//  Copyright © 2016年 van7ish. All rights reserved.
//

#import "CloudSecondViewController.h"
#import "BookTableViewCell.h"
#import "SubVideoTableViewCell.h"
#import "ZRTableView.h"
#import "BookDetailViewController.h"
#import "MagazineTableViewCell.h"
#import "MagazineDetailViewController.h"

@interface CloudSecondViewController () <UITableViewDelegate, UITableViewDataSource>

/** 导航条 */
@property (nonatomic, strong) UIImageView * navBar;
/** 按钮背景视图 */
@property (nonatomic, strong) UIView * backViewButtons;
@property (nonatomic, strong) UIScrollView * backViewTables;
@property (nonatomic, strong) ZRTableView * tableViews;
@property (nonatomic, strong) NSMutableArray * dataSource;
@property (nonatomic, strong) NSMutableArray * buttonArr;
@property (nonatomic, strong) UIScrollView * buttonScrollView;
/** 视频播放器 */
@property (nonatomic, strong) MPMoviePlayerViewController * player;

@end

@implementation CloudSecondViewController

- (MPMoviePlayerViewController *)player{
    if (!_player) {
        _player = [[MPMoviePlayerViewController alloc] init];
        _player.moviePlayer.shouldAutoplay = YES;
        _player.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;

    }
    return _player;
}

- (UIScrollView *)backViewTables{
    if (!_backViewTables) {
        _backViewTables = [[UIScrollView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.backViewButtons.frame), SCREEN_W, SCREEN_H - 72 - HeightScale((45 - 15)))];
        _backViewTables.contentSize = CGSizeMake(SCREEN_W * self.dataArr.count, _backViewTables.frame.size.height);
        _backViewTables.showsHorizontalScrollIndicator = NO;
        _backViewTables.backgroundColor = COLOR_LIGHTBGCOLOR;
        _backViewTables.pagingEnabled = YES;
        _backViewTables.delegate = self;
        
        for (int i = 0; i < self.dataArr.count; i ++) {
            self.tableViews = [[ZRTableView alloc] initWithFrame:CGRectMake(i * SCREEN_W, 0, SCREEN_W, _backViewTables.frame.size.height) style:UITableViewStylePlain];
            self.tableViews.delegate = self;
            self.tableViews.dataSource = self;
            self.tableViews.tag = 10 + i;
            self.tableViews.tableFooterView = [UIView new];
            self.tableViews.backgroundColor = COLOR_LIGHTBGCOLOR;
            self.tableViews.dataArr = [NSMutableArray array];
            if (self.resourceType == 1 || self.resourceType == 7 || self.resourceType == 8) {
                self.tableViews.rowHeight = SCREEN_W / 2.6;
            } else if (self.resourceType == 2 || self.resourceType == 9) {
                self.tableViews.rowHeight = SCREEN_W / 2.85;
            }
            
            [_backViewTables addSubview:self.tableViews];
        }
    }
    return _backViewTables;
}

- (UIView *)backViewButtons{
    if (!_backViewButtons) {
        _backViewButtons = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.navBar.frame) - HeightScale(15), SCREEN_W, HeightScale(45))];
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, HeightScale(15))];
        imageView.image = ImageNamed(@"yuanjiao");

        UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, HeightScale(15), SCREEN_W, HeightScale(30))];
        self.buttonScrollView = scrollView;
        scrollView.showsHorizontalScrollIndicator = NO;
        
        CGFloat buttonX, buttonW ;
        buttonX = WidthScale(8);
        NSMutableArray *buttonArr = [NSMutableArray array];
        self.buttonArr = buttonArr;
        for (int i = 0; i < self.dataArr.count; i ++) {
            buttonW = [self.dataArr[i][@"name"] length] * 18;
            UIButton *tagButton = [[UIButton alloc] initWithFrame:CGRectMake(buttonX, HeightScale(2), WidthScale(buttonW), HeightScale(26))];
            buttonX += buttonW + WidthScale(8);
            [tagButton setTitle:self.dataArr[i][@"name"] forState:UIControlStateNormal];
            [tagButton setTitleColor:COLOR_WHITE forState:UIControlStateNormal];
            [tagButton setBackgroundImage:ImageNamed(@"buttonBack_d") forState:UIControlStateNormal];
            [tagButton setBackgroundImage:ImageNamed(@"buttonBack") forState:UIControlStateSelected];
            tagButton.titleLabel.font = FONTSIZE(14);
            tagButton.layer.cornerRadius = WidthScale(6);
            tagButton.layer.masksToBounds = YES;
            tagButton.titleLabel.adjustsFontSizeToFitWidth = YES;
            tagButton.tag = 10 + i;
            [scrollView addSubview:tagButton];
            scrollView.contentSize = CGSizeMake(buttonX, HeightScale(30));
            [buttonArr addObject:tagButton];
            
            if (i == 0) {
                tagButton.selected = YES;
            }
            
            __weak typeof(self)weakSelf = self;
            [tagButton initWithBlock:^(UIButton *button) {
                
                DLog(@"%@", button.titleLabel.text);
                for (UIButton *deButton in buttonArr) {
                    deButton.selected = NO;
                }
                if (!button.selected) {
                    button.selected = YES;
                }
                [UIView animateWithDuration:0.2 animations:^{
                    
                    weakSelf.backViewTables.contentOffset = CGPointMake(SCREEN_W * i, 0);
                    ZRTableView *tableView = (ZRTableView *)[weakSelf.backViewTables viewWithTag:10 + i];
                    if (tableView.loadedData == NO) {
                        [weakSelf requestData:i];
                        tableView.loadedData = YES;
                    }
                    
                    if (scrollView.contentSize.width > SCREEN_W) {
                        if (button.center.x > SCREEN_W / 2 && ((scrollView.contentSize.width - button.center.x) > SCREEN_W / 2)) {
                            scrollView.contentOffset = CGPointMake(button.center.x - SCREEN_W / 2, 0);
                        } else if (button.center.x > SCREEN_W / 2 && (scrollView.contentSize.width - button.center.x) < SCREEN_W / 2) {
                            scrollView.contentOffset = CGPointMake(scrollView.contentSize.width - SCREEN_W, 0);
                        } else {
                            scrollView.contentOffset = CGPointMake(0, 0);
                        }
                    }
                    
                }];
                
            } for:UIControlEventTouchUpInside];
        }
        
        
        [_backViewButtons addSubview:scrollView];
        [_backViewButtons addSubview:imageView];
    }
    return _backViewButtons;
}

- (UIImageView *)navBar{
    if (!_navBar) {
        _navBar = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 72)];
        _navBar.image = ImageNamed(@"daohangtiao");
        _navBar.userInteractionEnabled = YES;
    }
    return _navBar;
}

#pragma mark - life cycle

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = COLOR_LIGHTBGCOLOR;
    
    [self.view addSubview:self.navBar];
    
    [self.view addSubview:self.backViewButtons];
    
    [self.view addSubview:self.backViewTables];
    
    [self requestData:0];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoFinished) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)dealloc{
    DLog(@"%s", __func__);
}

#pragma mark - MPMoviePlayerPlaybackDidFinishNotification Method

- (void)videoFinished{
    DLog(@"停止播放");
    if (self.player) {
        self.player = nil;
    }
}

- (void)noMoreVideos{
    
    for (UIView *subView in self.player.view.subviews) {
        DLog(@"%@", subView);
        for (UIView *subview in subView.subviews) {
            DLog(@"subView %@", subview);
            for (UIView *subView2 in subview.subviews) {
                for (UIView *subview3 in subView2.subviews) {
                    for (UIView *subview4 in subview3.subviews) {
                        for (UIView *subview5 in subview4.subviews) {
                            if ([subview5 isKindOfClass:[UIButton class]]) {
                                DLog(@"%@", subview5);
                                if (subview5.frame.size.width == 32) {
                                    UIButton *button = (UIButton *)subview5;
                                    [button removeTarget:nil
                                                  action:NULL
                                        forControlEvents:UIControlEventAllEvents];
                                    [button initWithBlock:^(id obj) {
                                        [ZRProgressHUD showMsgWithoutView:@"没有更多了"];
                                    } for:UIControlEventTouchUpInside];
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

#pragma mark - UITableViewDelegate Methods

- (NSInteger)tableView:(ZRTableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return tableView.dataArr.count;
}

- (UITableViewCell *)tableView:(ZRTableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.resourceType == 1) {
        static NSString *cellID = @"bookCell";
        BookTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell = [[BookTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
        
        cell.titleLabel.text = [NSString stringWithFormat:@"%@", tableView.dataArr[indexPath.row][@"name"]];
        cell.descLabel.text = [NSString stringWithFormat:@"%@", tableView.dataArr[indexPath.row][@"summaryText"]];
        cell.authorLabel.text = [NSString stringWithFormat:@"%@", [tableView.dataArr[indexPath.row][@"author"] length] ? tableView.dataArr[indexPath.row][@"author"] : @"连环画"];
        
        NSString *coverImageFile = [NSString stringWithFormat:@"%@%@", KHostAddress, tableView.dataArr[indexPath.row][@"coverImageFile"]];
        [cell.coverImageView sd_setImageWithURL:[NSURL URLWithString:coverImageFile] placeholderImage:ImageNamed(@"placeholdershuji")];
        
        return cell;
    } else if (self.resourceType == 2) {
        static NSString *cellID = @"videoCell";
        
        SubVideoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell = [[SubVideoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
        [cell.coverImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@", KHostAddress, tableView.dataArr[indexPath.row][@"coverImageFile"]]] placeholderImage:ImageNamed(@"placeholdershipin")];
        
        cell.timeLabel.text = [Tool dateConvert:[NSString stringWithFormat:@"%@", tableView.dataArr[indexPath.row][@"publishTime"]]];

        cell.titleLabel.text = [NSString stringWithFormat:@"【%@】", tableView.dataArr[indexPath.row][@"name"]];
        
        cell.authorLabel.text = tableView.dataArr[indexPath.row][@"author"];
        
        cell.descLabel.text = tableView.dataArr[indexPath.row][@"summarytext"];
        
        return cell;
    } else if (self.resourceType == 7) {
        static NSString *cellID = @"bookCell";
        BookTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell = [[BookTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
        
        cell.titleLabel.text = [NSString stringWithFormat:@"%@", tableView.dataArr[indexPath.row][@"name"]];
        cell.descLabel.text = [NSString stringWithFormat:@"%@", tableView.dataArr[indexPath.row][@"summaryText"]];
        cell.authorLabel.text = [NSString stringWithFormat:@"%@", [tableView.dataArr[indexPath.row][@"author"] length] ? tableView.dataArr[indexPath.row][@"author"] : @"连环画"];
        
        NSString *coverImageFile = [NSString stringWithFormat:@"%@%@", KHostAddress, tableView.dataArr[indexPath.row][@"coverImageFile"]];
        [cell.coverImageView sd_setImageWithURL:[NSURL URLWithString:coverImageFile] placeholderImage:ImageNamed(@"placeholdershuji")];
        
        return cell;
    } else if (self.resourceType == 8) {
        
        static NSString *cellID = @"magazineCell";
        MagazineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell = [[MagazineTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
        
        
        
        cell.titleLabel.text = [NSString stringWithFormat:@"%@", tableView.dataArr[indexPath.row][@"name"]];
        cell.descLabel.text = tableView.dataArr[indexPath.row][@"summarytext"];
        
        cell.timeLabel.text = [Tool dateConvert:[NSString stringWithFormat:@"%@", tableView.dataArr[indexPath.row][@"addtime"]]];
        
        NSString *coverimgpath = [NSString stringWithFormat:@"%@%@", KHostAddress, tableView.dataArr[indexPath.row][@"coverimgpath"]];
        [cell.coverImageView sd_setImageWithURL:[NSURL URLWithString:coverimgpath] placeholderImage:ImageNamed(@"placeholdershuji")];
        
        return cell;
        
    } else {//resourceType == 9
        static NSString *cellID = @"videoCell";
        
        SubVideoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        if (!cell) {
            cell = [[SubVideoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
        [cell.coverImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@", KHostAddress, tableView.dataArr[indexPath.row][@"coverImageFile"]]] placeholderImage:ImageNamed(@"placeholdershipin")];
        
        cell.timeLabel.text = [Tool dateConvert:[NSString stringWithFormat:@"%@", tableView.dataArr[indexPath.row][@"publishTime"]]];
        
        cell.titleLabel.text = [NSString stringWithFormat:@"【%@】", tableView.dataArr[indexPath.row][@"name"]];
        
        cell.authorLabel.text = tableView.dataArr[indexPath.row][@"author"];
        
        cell.descLabel.text = tableView.dataArr[indexPath.row][@"summarytext"];
        
        return cell;
    }
}

- (void)tableView:(ZRTableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.resourceType == 1) {
        //书籍
        BookDetailViewController *bookDetailVC = [[BookDetailViewController alloc] init];
        bookDetailVC.bookDic = tableView.dataArr[indexPath.row];
        [self.navigationController pushViewController:bookDetailVC animated:YES];
    } else if (self.resourceType == 2) {
        //视频
        DLog(@"播放视频");
        if ([tableView.dataArr[indexPath.row][@"filePath"] isKindOfClass:[NSNull class]]) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"视频地址不存在" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
        } else {
            NSString *url = [NSString stringWithFormat:@"%@%@", KHostAddress, tableView.dataArr[indexPath.row][@"filePath"]];
            self.player.moviePlayer.contentURL = [NSURL URLWithString:url];
            [self presentViewController:self.player animated:YES completion:^{
                [self requestHistory:indexPath ID:tableView.dataArr[indexPath.row][@"did"]];
                [self requestStatistics:indexPath ID:tableView.dataArr[indexPath.row][@"id"]];
                [self requestAddShelfOfVideo:tableView.dataArr[indexPath.row][@"id"]];
                [self noMoreVideos];
            }];
        }
    } else if (self.resourceType == 7) {
        //泛舟书海
        BookDetailViewController *bookDetailVC = [[BookDetailViewController alloc] init];
        bookDetailVC.bookDic = tableView.dataArr[indexPath.row];
        [self.navigationController pushViewController:bookDetailVC animated:YES];
    } else if (self.resourceType == 8) {
        //漫步看林
        MagazineDetailViewController *magazineDetailVC = [[MagazineDetailViewController alloc] init];
        magazineDetailVC.magazineDic = tableView.dataArr[indexPath.row];
        [self.navigationController pushViewController:magazineDetailVC animated:YES];
    } else {
        //奇妙影院
        DLog(@"播放视频");
        if ([tableView.dataArr[indexPath.row][@"filePath"] isKindOfClass:[NSNull class]]) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"视频地址不存在" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
        } else {
            NSString *url = [NSString stringWithFormat:@"%@%@", KHostAddress, tableView.dataArr[indexPath.row][@"filePath"]];
            self.player.moviePlayer.contentURL = [NSURL URLWithString:url];
            [self presentViewController:self.player animated:YES completion:^{
                [self requestHistory:indexPath ID:tableView.dataArr[indexPath.row][@"did"]];
                [self requestStatistics:indexPath ID:tableView.dataArr[indexPath.row][@"id"]];
                [self requestAddShelfOfVideo:tableView.dataArr[indexPath.row][@"id"]];
                [self noMoreVideos];
            }];
        }
    }
}

#pragma mark - UIScrollViewDelegate Method

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (self.backViewTables.contentOffset.x < - 50) {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    if ([scrollView isEqual:self.backViewTables]) {
        NSInteger index = scrollView.contentOffset.x / SCREEN_W;
        DLog(@"减速停止 %ld", index);
        
        
        ZRTableView *tableView = (ZRTableView *)[self.backViewTables viewWithTag:10 + index];
        if (tableView.loadedData == NO) {
            [self requestData:index];
            tableView.loadedData = YES;
        }
        
        UIButton *button = (UIButton *)[self.backViewButtons viewWithTag:10 + index];
        for (UIButton *tempButton in self.buttonArr) {
            tempButton.selected = NO;
        }
        button.selected = YES;
        
        if (self.buttonScrollView.contentSize.width > SCREEN_W) {
            [UIView animateWithDuration:0.2 animations:^{
                if (button.center.x > SCREEN_W / 2 && ((self.self.buttonScrollView.contentSize.width - button.center.x) > SCREEN_W / 2)) {
                    self.buttonScrollView.contentOffset = CGPointMake(button.center.x - SCREEN_W / 2, 0);
                } else if (button.center.x > SCREEN_W / 2 && (self.buttonScrollView.contentSize.width - button.center.x) < SCREEN_W / 2) {
                    self.buttonScrollView.contentOffset = CGPointMake(self.buttonScrollView.contentSize.width - SCREEN_W, 0);
                } else {
                    self.buttonScrollView.contentOffset = CGPointMake(0, 0);
                }
            }];
        }
    }
    
}

#pragma mark - data request

- (void)requestData:(NSInteger)index{
    if (self.resourceType == 1) {
        //书籍
        NSString *URL = [NSString stringWithFormat:KgetBookByClick, KHostAddress, KOrganizationID, @(1), self.dataArr[index][@"categoryType"], self.dataArr[index][@"code"], @(1)];
        [ZRRequestManager POST:URL parameters:nil success:^(id responseObject) {
            DLog(@"%@", responseObject);
            if ([[responseObject objectForKey:@"error"] integerValue] == 0) {

                self.dataSource = [NSMutableArray arrayWithArray:responseObject[@"data"][@"items"]];

                ZRTableView *tableView = (ZRTableView *)[self.backViewTables viewWithTag:10 + index];
                tableView.dataArr = self.dataSource;
                tableView.loadedData = YES;
                [tableView reloadData];
                
            } else {
                DLog(@"没有数据");
            }
            
        } failure:^(NSError *error) {
            DLog(@"%@", error);
        }];
    } else if (self.resourceType == 2) {
        //视频
        NSString *URL = [NSString stringWithFormat:KgetVideoByClick, KHostAddress, KOrganizationID, @(1), self.dataArr[0][@"categoryType"], self.dataArr[index][@"code"], @(1)];
        [ZRRequestManager POST:URL parameters:nil success:^(id responseObject) {
            DLog(@"%@", responseObject);
            if ([[responseObject objectForKey:@"error"] integerValue] == 0) {
                self.dataSource = [NSMutableArray arrayWithArray:responseObject[@"data"][@"items"]];
                ZRTableView *tableView = (ZRTableView *)[self.backViewTables viewWithTag:10 + index];
                tableView.dataArr = self.dataSource;
                [tableView reloadData];
            } else {
                DLog(@"没有数据");
            }
            
        } failure:^(NSError *error) {
            DLog(@"%@", error);
        }];
    } else if (self.resourceType == 7) {
        //泛舟书海
        NSString *URL = [NSString stringWithFormat:KgetBookByClick, KHostAddress, KOrganizationID, @(1), self.dataArr[index][@"categoryType"], self.dataArr[index][@"code"], @(1)];
        [ZRRequestManager POST:URL parameters:nil success:^(id responseObject) {
            DLog(@"%@", responseObject);
            
            if ([[responseObject objectForKey:@"error"] integerValue] == 0) {
                self.dataSource = [NSMutableArray arrayWithArray:responseObject[@"data"][@"items"]];
                
                ZRTableView *tableView = (ZRTableView *)[self.backViewTables viewWithTag:10 + index];
                tableView.dataArr = self.dataSource;
                tableView.loadedData = YES;
                [tableView reloadData];

            } else {
                DLog(@"没有数据");
            }
        } failure:^(NSError *error) {
            DLog(@"%@", error);
        }];
        
    } else if (self.resourceType == 8) {
        //漫步刊林
        NSString *URL = [NSString stringWithFormat:KgetMagazineByClick, KHostAddress, KOrganizationID, @(1), self.dataArr[index][@"id"], @(1)];
        [ZRRequestManager POST:URL parameters:nil success:^(id responseObject) {
            DLog(@"%@", responseObject);
            if ([responseObject[@"data"] isKindOfClass:[NSDictionary class]]) {
                self.dataSource = [NSMutableArray arrayWithArray:responseObject[@"data"][@"items"]];
                
                ZRTableView *tableView = (ZRTableView *)[self.backViewTables viewWithTag:10 + index];
                tableView.dataArr = self.dataSource;
                tableView.loadedData = YES;
                [tableView reloadData];
            }
        } failure:^(NSError *error) {
            DLog(@"%@", error);
        }];
        
    } else if (self.resourceType == 9) {
        //奇妙影院
        NSString *URL = [NSString stringWithFormat:KgetVideoByClick, KHostAddress, KOrganizationID, @(1), self.dataArr[index][@"categoryType"], self.dataArr[index][@"code"], @(1)];
        [ZRRequestManager POST:URL parameters:nil success:^(id responseObject) {
            DLog(@"%@", responseObject);
            if ([responseObject[@"data"] isKindOfClass:[NSDictionary class]]) {
                self.dataSource = [NSMutableArray arrayWithArray:responseObject[@"data"][@"items"]];
                ZRTableView *tableView = (ZRTableView *)[self.backViewTables viewWithTag:10 + index];
                tableView.dataArr = self.dataSource;
                tableView.loadedData = YES;
                [tableView reloadData];
            }
            
        } failure:^(NSError *error) {
            DLog(@"%@", error);
        }];
    }
}

/** 添加浏览历史(视频) */
- (void)requestHistory:(NSIndexPath *)indexPath ID:(NSString *)ID{
    //判断是否登录
    if ([AppDelegate shareDelegate].userModel) {
        NSString *URL = [NSString stringWithFormat:KaddHistory, KHostAddress, ID, @(2), KOrganizationID, [AppDelegate shareDelegate].userModel.userId];
        [ZRRequestManager POST:URL parameters:nil success:^(id responseObject) {
            DLog(@"添加浏览历史");
        } failure:^(NSError *error) {
            DLog(@"添加浏览历史失败");
        }];
    }
}

/** 添加统计 */
- (void)requestStatistics:(NSIndexPath *)indexPath ID:(NSString *)ID{
    //判断是否登录
    if ([AppDelegate shareDelegate].userModel) {
        //1、图书；2、视频；3、音频；4、期刊杂志5、县域视频6、资讯
        NSString *URL = [NSString stringWithFormat:Kstatistics, KHostAddress, KCurrentIP, [AppDelegate shareDelegate].userModel.userId, KOrganizationID, @(2), ID];
        [ZRRequestManager POST:URL parameters:nil success:^(id responseObject) {
            if ([[responseObject objectForKey:@"error"] integerValue] == 0) {
                DLog(@"添加统计成功");
            } else {
                DLog(@"添加统计失败");
            }
        } failure:^(NSError *error) {
            DLog(@"%@", error);
        }];
    }
}

/** 视频添加到书架 */
- (void)requestAddShelfOfVideo:(NSString *)ID{
    if ([AppDelegate shareDelegate].userModel) {
        NSString *URL = [NSString stringWithFormat:KaddShelf, KHostAddress, ID, @(2), KOrganizationID, [AppDelegate shareDelegate].userModel.userId];
        [ZRRequestManager POST:URL parameters:nil success:^(id responseObject) {
            if ([[responseObject objectForKey:@"error"] integerValue] == 0) {
                DLog(@"添加书架成功");
            } else {
                DLog(@"添加书架失败");
            }
            
            
        } failure:^(NSError *error) {
            DLog(@"添加书架失败");
        }];
    }
}

@end
